import 'package:enterprise_v6_app/app/components/special_operation/custom_file_upload_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_icon_title_view.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_relation_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_work_user_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_ticket/application/height_job_application/height_job_application_controller.dart';

///高处作业-作业申请
class HeightJobApplicationPage extends StatelessWidget {
  HeightJobApplicationPage({required this.isEnabled, required this.isChange, super.key});

  //节点是否可编辑
  final bool isEnabled;

  // 是否在交接班中
  final bool isChange;

  final controller = Get.put(HeightJobApplicationController());

  /// 获取基本作业信息
  Widget _getBasicJobWidget() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          const CustomIconTitleView(
            title: '作业基本信息',
          ),
          Container(
            color: const Color(0xFFF5F7FC),
            height: 1.w,
          ),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 13.w),
            child: Column(
              children: [
                CustomInputPage(
                  title: '作业编号',
                  isEnabled: isEnabled && !isChange,
                  text: controller.executeTicketReceipt.receiptNo,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.receiptNo = value;
                  },
                ),
                CustomSelectPage(
                    title: '计划作业时间',
                    selectText:
                        '${controller.executeTicketReceipt.ticketPlanList!.planStartDate}\n        至\n${controller.executeTicketReceipt.ticketPlanList!.planEndDate}',
                    isEnabled: false,
                    onCallBack: () {}),
                CustomHighInputPage(
                  title: '作业内容',
                  text: controller.executeTicketReceipt.ticketPlanList!.ticketContent,
                  onCallBack: (value) {},
                  isEnabled: false,
                  isShowDivider: false,
                ),
                CustomInputPage(
                  title: '申请单位',
                  text: controller.executeTicketReceipt.ticketPlanList!.applyDepartmentName,
                  onCallBack: (value) {},
                  isEnabled: false,
                ),
                CustomSelectPage(
                    title: '作业申请时间',
                    isEnabled: isEnabled && !isChange,
                    selectText: controller.executeTicketReceipt.applyDate!,
                    onCallBack: () {
                      controller.showDatePicker();
                    }),
                CustomInputPage(
                  title: '作业高度(m)',
                  textInputType: TextInputType.number,
                  isEnabled: isEnabled && !isChange,
                  text: controller.executeTicketReceipt.workOtherDataDTO!.operatorHeight!,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.operatorHeight = value;
                  },
                ),
                CustomInputPage(
                  title: '高处作业级别',
                  isEnabled: isEnabled && !isChange,
                  text: controller.executeTicketReceipt.workOtherDataDTO!.heightLevel!,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.heightLevel = value;
                  },
                ),
                // CustomSelectPage(
                //     title: '高处作业级别',
                //     selectText: controller. executeTicketReceipt.workOtherDataDTO!.heightLevel!,
                //     hintText: '填写高度后点击',
                //     isEnabled: true,
                //     onCallBack: () {
                //       controller.changeHighLevel();
                //     }),
                CustomFileUploadPage(
                  isRequired: false,
                  isShowDivider: false,
                  isEnabled: isEnabled,
                  isChange: isChange,
                  uploadedFiles: controller.executeTicketReceipt.workPlan,
                  title: '作业方案：',
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workPlan = value;
                    controller.update();
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  ///获取作业人信息
  Widget _getWorkUserView() {
    return CustomSelectWorkUserPage(
        title: '作业人',
        isEnabled: isEnabled && !isChange,
        operatorType: 0,
        queryParameters: const {
          'roleName': '作业人',
        },
        dataList: controller.executeTicketReceipt.operatorLists,
        onCallBack: (value) {
          controller.executeTicketReceipt.operatorLists = value;
        });
  }

  ///获取作业负责人信息
  Widget _getUnitLeaderView() {
    return CustomSelectWorkUserPage(
        title: '作业负责人',
        isEnabled: isEnabled && !isChange,
        operatorType: 1,
        isShowCertificateNumber: false,
        queryParameters: const {
          'roleName': '作业负责人',
        },
        dataList: controller.executeTicketReceipt.operatorLists,
        onCallBack: (value) {
          controller.executeTicketReceipt.operatorLists = value;
        });
  }

  ///获取监护人信息
  Widget _getGuardianView() {
    return CustomSelectWorkUserPage(
        title: '监护人',
        isEnabled: isEnabled && !isChange,
        operatorType: 2,
        isShowCertificateNumber: false,
        queryParameters: const {
          'roleName': '监护人',
        },
        dataList: controller.executeTicketReceipt.operatorLists,
        onCallBack: (value) {
          controller.executeTicketReceipt.operatorLists = value;
        });
  }

  ///获取剩余信息
  Widget _getRemainingView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 13.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          CustomSelectPage(
              isEnabled: isEnabled && !isChange,
              title: '作业单位',
              selectText: controller.executeTicketReceipt.workDepartmentName!,
              onCallBack: () {
                controller.applyUnitSelect();
              }),
          CustomSelectRelationPage(
            isEnabled: isEnabled && !isChange,
            selectedWork: controller.executeTicketReceipt.otherTicketNo,
            onCallBack: (value) {
              controller.executeTicketReceipt.otherTicketNo = value;
            },
            isShowDivider: false,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
      margin: EdgeInsets.only(bottom: 60.w),
      color: const Color(0xFFF5F5F6),
      alignment: Alignment.topCenter,
      child: GetBuilder(
          init: controller,
          builder: (_) {
            if (controller.executeTicketReceipt.id!.isEmpty) {
              return Container();
            }
            // if (controller.operatorHeightController.text.isNotEmpty) {
            //   controller.changeHighLevel();
            // }
            return SingleChildScrollView(
                child: Column(
              children: [
                // 作业基本信息
                _getBasicJobWidget(),
                AppGaps.vGap20,
                // 作业人员信息
                _getWorkUserView(),
                AppGaps.vGap20,
                // 负责人
                _getUnitLeaderView(),
                AppGaps.vGap20,
                // 监护人
                _getGuardianView(),
                AppGaps.vGap20,
                // 剩余信息
                _getRemainingView(),
              ],
            ));
          }),
    );
  }
}
